package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.entity.GongYing;
import com.itqf.entity.Product;
import com.itqf.mapper.ProductMapper;
import com.itqf.service.ProductService;
import com.itqf.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者:高少东
 * 项目名:  product_gsd
 * 时间: 2019/12/19 17:06
 * 描述:
 */

@Service
public class ProductServiceimpl implements ProductService {


    @Autowired
    ProductMapper productMapper;

    /**
     *  查询所有商品 以及 页面查询 下拉框数据
     * @param currentPage
     * @param pageSize
     * @return
     */

    @Override
    public ProductVo selectAllProduct(Integer currentPage,Integer pageSize) {

       List<GongYing> gongYings = productMapper.selectAllGy();

        PageHelper.startPage(currentPage,pageSize);
       List<Product> products = productMapper.selectAllPro();

        PageInfo<Product> pageInfo = new PageInfo<>(products);


       ProductVo productVo = new ProductVo(gongYings,pageInfo);
        return productVo;
    }

    /**
     *  模糊查询商品信息
     * @param product
     * @return
     */
    @Override
    public List<Product> queryProduct(Product product) {

          Product product1 = new Product();
          product1.setProName("%"+product.getProName()+"%");
          product1.setGId(product.getGId());
          product1.setProPutaway(product.getProPutaway());
        List<Product> products = productMapper.queryProduct(product1);
        return products;
    }

    /**
     *  添加商品
     * @param product
     * @return
     */
    @Override
    public int addProduct(Product product) {

       int rows= productMapper.addProduct(product);
        return rows;
    }

    /**
     *  删除商品
     * @param product
     * @return
     */
    @Override
    public int deleteProduct(Product product) {

       int rows= productMapper.deleteProduct(product);
        return rows;
    }

    /**
     *   修改商品
     * @param product
     * @return
     */
    @Override
    public int modifyProduct(Product product) {

      int rows =productMapper.modifyProduct(product);
        return rows;
    }
}
